﻿//-- =============================================
//-- Author:	    Saghari, Farid
//-- Create date:   1390/01/10
//-- Description:	Business Object Base Class
//-- E-Mail:    	fredmcs@live.com
//-- Mobile:        0937-241-3499
//-- Last Update:   1390/01/10 14:30
//-- =============================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChequeManagement.BLL
{
    /// <summary>
    /// this class contain field,property,method
    /// </summary>
    public abstract class BaseObject
    {
        private List<string> errorsList = null;

        /// <summary>
        /// this method check that arg parameter is null or not null,if is null ,add a error to errorsList that error text is on errDetail parameter
        /// </summary>
        /// <param name="errDetail" Type="string"></param>
        /// <param name="arg" Type="object"></param>
        /// <return>this type is void and Do not return</return>
        public void AddError(string errDetail, object arg)
        {
            if (errorsList == null)
                errorsList = new List<string>();

            if (arg == null)
                errorsList.Add(errDetail);
            else
                errorsList.Add(string.Format(errDetail, arg));

        }

        /// <summary>
        /// this property contain "get" that check if errorsList is null return null
        /// else return each error on errorsList 
        /// this property is read only
        /// </summary>
        /// <return>this type is void and Do not return</return>
        public string Errors
        {
            get
            {
                if (errorsList == null)
                    return (string.Empty);
                else
                {
                    StringBuilder sb = new StringBuilder();
                    int errNumber = 0;

                    foreach (string errText in errorsList)
                    {
                        errNumber++;
                        sb.AppendFormat("{0}: {1}", errNumber, errText);
                    }
                    return (sb.ToString());
                }
            }
        }

        /// <summary>
        /// this property contain "get" that check errorsList if errorsList is null return zero
        /// else errorsList not null return count error on errorsList
        /// this property is read only
        /// </summary>
        /// <return>this type is void and Do not return</return>
        public int ErrorsCount
        {
            get
            {
                if (errorsList == null)
                    return (0);
                else
                    return (errorsList.Count);
            }
        }

    }
}
